<?php

/**
 * Created by PhpStorm.
 * User: dev
 * Date: 23/9/14
 * Time: 12:56 PM
 */
class Admin_Settings_Seo_Controller extends Admin_Controller
{

    public $restful = true;

    public function __construct()
    {
        parent::__construct();
        //--Your Code --//
        $this->theme->set_theme("admin");
        $this->theme->set_layout("default");


    }

    public function get_index()
    {
    	if (Auth::guest()) return Redirect::to('admin/login');
    	 
    	if (!Auth::check())
    	{
    		return Redirect::to('admin/login');
    	}else{
        $data['lang'] = $this->lang;
        $data['title'] = Settings::get($this->lang, 'site_title');
        $this->theme->title("Application Settings");
        return $this->theme->render('admin::settings.seo', $data);
    	}
    }

    public function post_index()
    {
        if (Input::get('btnSave') == 'save') {

        	$rules = array(
        			
        			'seo_listing_title' => 'required',
        			'seo_search_title' => 'required',
        			);
        	
        	
        	$validator = Validator::make(Input::get(), $rules);
        	if( $validator->fails() )
        	{
        		return Redirect::back()->with_input()->with_errors($validator)->with('message','<div class="alert alert-danger">Invalid Operation !</div>');
        	
        	}else{
        	
        	Settings::saveSetting('seo_listing_title', trim(Input::get('seo_listing_title')));
            Settings::saveSetting('seo_listing_keyword', trim(Input::get('seo_listing_keyword')));
            Settings::saveSetting('seo_listing_description', trim(Input::get('seo_listing_description')));

            Settings::saveSetting('seo_search_title', trim(Input::get('seo_search_title')));
            Settings::saveSetting('seo_search_keyword', trim(Input::get('seo_search_keyword')));
            Settings::saveSetting('seo_search_description', trim(Input::get('seo_search_description')));
        	}
        }
        return Redirect::back()->with('message','<div class="alert alert-info">Settings Updated...</div>');
    }
}
